﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class Admin_addpicture : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btAdd_Click(object sender, EventArgs e)
    {
        if (String.IsNullOrEmpty(fhFileName.Value)) 
            return;
        Picture picture = new Picture();
        picture.Category = ddlCatalog.SelectedValue;
        picture.ImageName = fhFileName.Value;
        PictureService.GetInstance().AddPicture(picture);
        Response.Redirect(ResolveUrl("~/Admin/pictureManagement.aspx"));
    }

    protected void btnUpload_Click(object sender, EventArgs e)
    {
        if (!FileUpload1.HasFile) 
            return;
            string fileName = DateTime.Now.Ticks.ToString() + ".jpeg";
            string destFilePath = Server.MapPath(@"~\pictures\tmp\") + fileName;
            string smallImgPath = Server.MapPath(@"~\pictures\tmp\small") + fileName;

            FileUpload1.SaveAs(destFilePath);

            PictureHelper.MakeThumbnail(destFilePath, smallImgPath, 102, 58, "HW");

            imgPreview.ImageUrl = Page.ResolveUrl(@"~\pictures\tmp\" + fileName);
            fhFileName.Value = fileName;
    }
}
